import request from "@/utils/request";

const Api = {
  home: "api/web/home/index",
  notice: "api/web/notice/index",
  noticeDetail: "api/web/notice/detail/",
  goodsList: "api/web/goods/lists",
  register: "api/web/register",
  login: "api/web/auth",
  logout: "api/logout",

  goodsDetails: "api/web/goods/detail/",
  userInfo: "api/web/current/",
  updatePassword: "api/web/current/passwd",
  // 地址
  address: "api/web/address/",
  addressDel: "api/web/address/destroy/",
  oauthCode: "api/web/oauth/code",
  order: "api/web/order/", //订单
  receipt: "api/web/order/receipt/", //确认收货
  orderCancel: "api/web/order/cancel/", //订单取消
  consignment: "api/web/order/sale/", //寄售
  payment: "api/web/order/payment/", //构建支付请求
  orderNum: "api/web/order/static", //订单数量
  oauthSure: "api/web/oauth/" //授权
};

function zpay() {
  return request({
    url: Api.oauthSure,
    method: "get"
  });
}

function orderNum(parameter) {
  return request({
    url: Api.orderNum,
    method: "get",
    params: parameter
  });
}

function payment(parameter) {
  return request({
    url: `${Api.payment}${parameter.id}`,
    method: "put"
  });
}

function consignment(parameter) {
  return request({
    url: `${Api.consignment}${parameter.id}`,
    method: "put"
  });
}

function orderCancel(parameter) {
  return request({
    url: `${Api.orderCancel}${parameter.id}`,
    method: "put"
  });
}

function receipt(parameter) {
  return request({
    url: `${Api.receipt}${parameter.id}`,
    method: "put"
  });
}

function orderDetails(parameter) {
  return request({
    url: `${Api.order}${parameter.id}`,

    method: "get"
  });
}

function logout(parameter) {
  return request({
    url: Api.logout,
    method: "get",
    params: parameter
  });
}

function orderList(parameter) {
  return request({
    url: Api.order,
    method: "get",
    params: parameter
  });
}

function orderCreate(parameter) {
  return request({
    url: Api.order,
    method: "post",
    data: parameter
  });
}

function addressList(parameter) {
  return request({
    url: Api.address,
    method: "get",
    params: parameter
  });
}

function oauthCode(parameter) {
  return request({
    url: Api.oauthCode,
    method: "put",
    data: parameter,
    headers: {
      Authorization: parameter.token
    }
  });
}

function createAddress(parameter) {
  return request({
    url: Api.address,
    method: "post",
    data: parameter
  });
}

function deleteAddress(parameter) {
  return request({
    url: `${Api.addressDel}${parameter.id}`,
    method: "put"
  });
}

function updateAddress(parameter) {
  return request({
    url: `${Api.address}${parameter.id}`,
    method: "put",
    data: parameter
  });
}

function updatePassword(parameter) {
  return request({
    url: Api.updatePassword,
    method: "put",
    data: parameter
  });
}

function userInfo(parameter) {
  return request({
    url: Api.userInfo,
    method: "get",
    params: parameter
  });
}

function getHome(parameter) {
  return request({
    url: Api.home,
    method: "get",
    params: parameter
  });
}

function getNotice(parameter) {
  return request({
    url: Api.notice,
    method: "get",
    params: parameter
  });
}

function getNoticeDetail(parameter) {
  return request({
    url: `${Api.noticeDetail}${parameter.id}`,
    method: "get"
  });
}

function getGoodsList(parameter) {
  return request({
    url: Api.goodsList,
    method: "get",
    params: parameter
  });
}

function register(parameter) {
  return request({
    url: Api.register,
    method: "post",
    data: parameter
  });
}

function login(parameter) {
  return request({
    url: Api.login,
    method: "post",
    data: parameter
  });
}

function getGoodsDetails(parameter) {
  return request({
    url: `${Api.goodsDetails}${parameter.id}`,
    method: "get"
  });
}

export default {
  zpay,
  getHome,
  getNotice,
  getNoticeDetail,
  getGoodsList,
  register,
  login,
  getGoodsDetails,
  userInfo,
  updatePassword,
  createAddress,
  addressList,
  updateAddress,
  deleteAddress,
  oauthCode,
  orderCreate,
  orderList,
  logout,
  orderDetails,
  receipt,
  orderCancel,
  consignment,
  payment,
  orderNum
};
